<template>
  <div>
    <el-form :inline="true" :model="seach" class="demo-form-inline" style="text-align: left">
      <el-form-item label="字典类型名称">
        <el-input v-model="seach.typeName" placeholder="字典类型名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getdictionarys()">查询</el-button>
        <el-button type="primary" @click="Add()">添加</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="DictionList" borderstyle="width: 100%">
      <el-table-column prop="id" label="主键Id" align="center">
      </el-table-column>
      <el-table-column prop="typeName" label="字典类型名称" align="center">
      </el-table-column>
      <el-table-column prop="state" label="是否启用" align="center">
        <template slot-scope="scope">
          {{ scope.row.state ? "启用" : "禁用" }}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="primary" @click="Upd(scope.row.id)">编辑</el-button>
          <el-button type="primary" @click="Disct(scope.row.id)">字典明细</el-button>
          <el-button type="primary" @click="UpdState(scope.row.id)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="公共字典类型" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="字典类型名称">
          <el-input v-model="form.typeName"></el-input>
        </el-form-item>
        <el-form-item label="排序ID">
          <el-input v-model="form.dicId"></el-input>
        </el-form-item>
        <el-form-item label="是否启用">
          <el-radio-group v-model="form.state">
            <el-radio :label="true">启用</el-radio>
            <el-radio :label="false">禁用</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="Servared">保 存</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  getdictionarysapi,
  addSStaffListapi,
  updatedictionarys,
} from "@/api/sysconfig/Dictionary";
export default {
  data() {
    return {
      seach: {
        typeName: "",
      },
      DictionList: [],
      dialogFormVisible: false,

      form: {
        typeName: "",
        dicId: "",
        state: "",
      },
    };
  },
  mounted() {
    this.getdictionarys();
  },
  methods: {
    // 获取字典类型列表
    getdictionarys() {
      var params = {
        typeName: this.seach.typeName,
      };
      getdictionarysapi(params).then(
        (res) => {
          this.DictionList = res.data.data;
        },
        (err) => {
          console.error(err);
        }
      );
    },
    Add() {
      this.dialogFormVisible = true;
    },
    Servared() {
      addSStaffListapi(this.form).then(
        (res) => {
          this.dialogFormVisible = false;
          this.getdictionarys();
        },
        (err) => {
          console.error(err);
        }
      );
    },
    Upd(Id) {
      this.$router.push("DictionaryUpd?id=" + Id);
    },
    Disct(Id) {
      this.$router.push("DetailsList?id=" + Id);
    },
    UpdState(Id) {
      var State = {
        id: Id,
      };
      updatedictionarys(State).then(
        (res) => {
          if (res.data.code == 0) {
            this.$message.success("修改成功");
            this.getdictionarys();
          }
        },
        (err) => {
          console.error(err);
        }
      );
    },
  },
};
</script>
<style></style>